import Mock from 'mockjs'
import loginAPI from './login'
import transactionAPI from './transaction'
import permissionAPI from './permission'

function applyResult(data) {
  if (typeof data === 'function') {
    return config => {
      var value = data(config)
      return {
        success: true,
        code: 200,
        data: value
      }
    }
  } else {
    return {
      success: true,
      code: 200,
      data: data
    }
  }
}

// 登录相关
Mock.mock(/\/login\/login/, 'post', applyResult(loginAPI.loginByUsername))
Mock.mock(/\/login\/logout/, 'post', applyResult(loginAPI.logout))
Mock.mock(/\/user\/info\.*/, 'get', applyResult(loginAPI.getUserInfo))

// 权限相关
Mock.mock(/\/user\/permissions/, 'get', applyResult(permissionAPI.getPermissions))

// 账单相关
Mock.mock(/\/transaction\/list/, 'get', applyResult(transactionAPI.getList))

export default Mock
